package com.das.mechanic_base.adapter.alone;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.alone.AloneNewBean;
import com.hjq.toast.ToastUtils;

import java.util.ArrayList;
import java.util.List;

public class X3AloneShowNumAdapter extends RecyclerView.Adapter<X3AloneShowNumAdapter.AloneShowNumHolder> {

    private Context mContext;

    private List<List<String>> isStatus;

    private List<AloneNewBean.ItemQuestionListBean> mList;

    private List<List<String>> contentList;

    public X3AloneShowNumAdapter(Context mContext) {
        this.mContext = mContext;
        this.mList = new ArrayList<>();
        this.isStatus = new ArrayList<>();
    }

    public void changeData(List<List<String>> isStatus, List<AloneNewBean.ItemQuestionListBean> aloneNewBeans,List<List<String>> contentList) {
        this.mList = aloneNewBeans;
        this.isStatus = isStatus;
        this.contentList = contentList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public AloneShowNumHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new AloneShowNumHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_alone_show_num_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull AloneShowNumHolder holder, int position) {
//        holder.tv_index.setText((position + 1 < 10) ? "0" + (position + 1) + "." : (position + 1) + ".");

        holder.tv_title.setText(mList.get(position).toItemDesc + "");

//        holder.rlv_num.setLayoutManager(new GridLayoutManager(mContext,5));
        holder.rlv_num.setLayoutManager(new LinearLayoutManager(mContext));
        List<String> tmpAnswer = null;
        if (position<contentList.size()){
            tmpAnswer = contentList.get(position);
        }

        X3NumAdapter numAdapter = new X3NumAdapter(mContext, isStatus.get(position),mList.get(position).questionDetectionTempletQuestionList,tmpAnswer, position);

        holder.rlv_num.setAdapter(numAdapter);

        numAdapter.setiOnClickJump((titleIndex, index) -> {
            if (iOnClickJump != null) {
                iOnClickJump.iOnClickJumpToIndex(titleIndex,index);
            }
        });

        holder.iv_pass_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (iOnClickJump != null) {
                    iOnClickJump.iOnClickItemPass(position,-1);
                }
            }
        });
    }

    IOnClickJump iOnClickJump;

    public void setiOnClickJump(IOnClickJump iOnClickJump) {
        this.iOnClickJump = iOnClickJump;
    }

    public interface IOnClickJump {
        void iOnClickJumpToIndex(int titleIndex,int index);
        void iOnClickItemPass(int titleIndex,int index);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class AloneShowNumHolder extends RecyclerView.ViewHolder {
//        TextView tv_index;
        TextView tv_title;
        RecyclerView rlv_num;
        ImageView iv_pass_all;
        public AloneShowNumHolder(@NonNull View itemView) {
            super(itemView);
//            tv_index = itemView.findViewById(R.id.tv_index);
            tv_title = itemView.findViewById(R.id.tv_title);
            rlv_num = itemView.findViewById(R.id.rlv_num);
            iv_pass_all = itemView.findViewById(R.id.iv_pass_all);
        }
    }
}
